package view.overlay;

public abstract class PassiveOverlay extends Overlay {
	
	private boolean mIsValid;
	
	public PassiveOverlay() {
		invalidate();
	}
	
	@Override
	public void imageRequested() {
		if (! isValid()) {
			// Force a redraw
			this.paint();
			
			// Make the image valid
			setValid(true);
		}
	}
	
	/**
	 * Sets the validity of the Overlay image to the
	 * passed boolean. Only this class and its subtypes
	 * may access this method directly. Clients
	 * may use <code>invalidate()</code> to set it to false.
	 * 
	 * @param isValid
	 */
	protected void setValid(boolean isValid) {
		mIsValid = isValid;
	}
	
	/**
	 * Returns the current State of this PassiveOverlay
	 * @return
	 */
	public boolean isValid() {
		return (mIsValid);
	}
	
	/**
	 * Sets the Overlay to be invalid. Typically
	 * called by subtypes.
	 */
	public void invalidate() {
		setValid(false);
	}
	
	@Override
	public void resize(int width, int height) {
		super.resize(width, height);
		
		this.invalidate();
	}

}
